package servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;


/**
 * 04-响应对象之输出内容
 * 需求：向浏览器输出"helloworld"、"你好世界"
 */
@WebServlet("/demo06")
public class Demo06Servlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //告诉服务器，以utf-8编码响应正文
        //response.setCharacterEncoding("utf-8");
        //告诉浏览器，以utf-8解码响应正文
        //response.setHeader("Content-Type","text/html;charset=utf-8");
        //告诉服务器，以utf-8编码响应正文 ；告诉浏览器，以utf-8解码响应正文。
        response.setContentType("text/html;charset=utf-8");
        String content = "你好世界";
        PrintWriter writer = response.getWriter();
        writer.write(content);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
